/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gray.swing;

import gray.Factory;
import gray.Field;
import java.awt.Container;
import java.math.BigDecimal;
import java.util.Date;
import gray.Frame;
import util.observer.Trigger;
import snippet.Snipet;
import gray.swing.button.Button;
import gray.swing.element.BigTextElem;
import gray.swing.element.TextElem;
import gray.swing.element.TitleElem;
import gray.swing.field.AdresseField;
import gray.swing.field.BigTextField;
import gray.swing.field.CheckField;
import gray.swing.field.ComboField;
import gray.swing.field.CpField;
import gray.swing.field.DateField;
import gray.swing.field.EmailField;
import gray.swing.field.IntegerField;

import gray.swing.field.MoneyField;
import gray.swing.field.NameField;
import gray.swing.field.PercentField;
import gray.swing.field.RadioField;
import gray.swing.field.TelephoneField;
import gray.swing.field.TextField;
import gray.swing.field.TimeField;
import gray.swing.field.UrlField;
import gray.swing.frame.BottomFrame;
import gray.swing.frame.LeftColumnFrame;
import gray.swing.frame.ListFrame;
import gray.swing.frame.RawFrame;
import gray.swing.frame.RightColumnFrame;
import gray.swing.frame.SplitFrame;
import gray.swing.frame.TopFrame;
import snippet.SnipetEN;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
 *
 * @author martin
 */
public final class FactorySwing implements Factory<Container>{
    private final JFrame _frame;
    private final Snipet _lang;
    
    private FactorySwing (final String title, final Snipet lang){
      _frame = new JFrame(title);
      _frame.setLocationRelativeTo(null);
      _frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      //_frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
      _frame.setVisible(true);
      //_frame.setSize(800, 600);
      _frame.setFocusable(true);
      _frame.setLocationRelativeTo(null);

      if (lang!=null)
        _lang=lang;
      else
        _lang=SnipetEN.singleton();
      
    }

    public static Factory<Container> makeWindow(final String title, final Snipet lang){
        return new FactorySwing(title,lang);
    }
    
    public static void messageError(final String msg){
        JOptionPane.showMessageDialog(null, msg, "erreur", JOptionPane.ERROR_MESSAGE);
    }
    
    @Override
    public void swap(Frame<Container> view){
        _frame.setContentPane(view.container());
        _frame.revalidate();
    }
    
    //button
    @Override
    public Frame<Container> button(final Trigger observer, final String name, final Character key){
        return Button.factory(observer, name, key);
    }
    
    @Override
    public Frame<Container> buttonWithMsg(final Trigger observer, final String name, final Character key, final Object msg){
        return Button.factoryWithMsg(observer, name, key, msg);
    }
    
    @Override
    public Frame<Container> buttonValid(final Trigger observer, final String name, final Character key, final Frame<Container> valid){
        return Button.factoryValid(observer, name, key, valid);
    }
    
    @Override
    public Frame<Container> buttonValidWithMsg(final Trigger observer, final String name, final Character key, final Object msg, final Frame<Container> valid){
        return Button.factoryValidWithMsg(observer, name, key, msg, valid);
    }
    
    //element
    @Override
    public Frame<Container> elemDate(final Date date){
        return TextElem.factoryDate(date);
    }
    
    @Override
    public Frame<Container> elemMoney(final BigDecimal num){
        return TextElem.factoryMoney(num);
    }
    
    @Override
    public Frame<Container> elemText(final String name){
        return TextElem.factoryTxt(name);
    }
    
    @Override
    public Frame<Container> elemTime(final Date hour){
        return TextElem.factoryTime(hour);
    }
    
    @Override
    public Frame<Container> elemString(final String num){
        return TextElem.factoryString(num);
    }
    
    @Override
    public Frame<Container> elemPercentage(final BigDecimal num){
        return TextElem.factoryPercentage(num);
    }
    
    //Frame
    @Override
    public Frame<Container> frameBottom(final Frame<Container> _bottom, final Frame<Container> _rest){
        return BottomFrame.factory(_bottom, _rest);
    }
    
    @Override
    public Frame<Container> frameTop(final Frame<Container> _top, final Frame<Container> _rest){
        return TopFrame.factory(_top, _rest);
    }
    
    @Override
    public Frame<Container> frameLeft(final Frame<Container> _left, final Frame<Container> _rest){
        return LeftColumnFrame.factory(_left, _rest);
    }
    
    @Override
    public Frame<Container> frameRight(final Frame<Container> _right, final Frame<Container> _rest){
        return RightColumnFrame.factory(_right, _rest);
    }
    
    @Override
    public Frame<Container> frameList(final Frame<Container> ... lst){
        return ListFrame.factory(lst);
    }
    
    @Override
    public Frame<Container> frameRaw(final Frame<Container> ... lst){
        return RawFrame.factory(lst);
    }
    
    @Override
    public Frame<Container> frameSplit(final Frame<Container> left, final Frame<Container> right){
        return SplitFrame.factory(left, right);
    }
    
    //field
    @Override
    public Field<String,Container> fieldBigText(final String name, final Character key){
        return BigTextField.factory(_lang, name, key);
    }
    
    @Override
    public Field<Boolean,Container> fieldCheckBox(final String name, final Character key){
        return CheckField.factory(_lang,name,key);
    }
    
    @Override
    public Field<String,Container> fieldComboBox(final String name, final String [] lst, final Character key){
        return ComboField.factory(_lang,name,lst, key);
    }
    
    @Override
    public Field<Date,Container> fieldDate(final String name, final Character key){
        return DateField.factory(_lang,name,key);
    }
    
    @Override
    public Field<BigDecimal,Container> fieldMoney(final String name, final Character key){
        return MoneyField.factory(_lang,name,key);
    }
    
    @Override
    public <E extends Enum<E>> Field<Enum<E>,Container> fieldRadio(final String title, Class <E> enumData, final Character[] key){
        return RadioField.factory(_lang,title, enumData, key);
    }
    
    @Override
    public Field<String,Container> fieldText(final String name, final Character key){
        return TextField.factory(_lang,name, key);
    }
    
    @Override
    public Field<Date,Container> fieldTime(final String name, final Character key){
        return TimeField.factory(_lang,name,key);
    }
    
    @Override
    public Field<BigDecimal,Container> fieldPercentage(final String name, final Character key){
        return PercentField.factory(_lang,name,key);
    }
    
    @Override
    public Field<Integer,Container> fieldInteger(final String name, final Character key){
        return IntegerField.factory(_lang,name,key);
    }
    

    //field required
    @Override
    public Field<Date,Container> fieldDateRequired(final String name, final Character key){
        return DateField.factoryRequired(_lang,name,key);
    }
    
    @Override
    public Field<BigDecimal,Container> fieldMoneyRequired(final String name, final Character key){
        return MoneyField.factoryRequired(_lang,name,key);
    }

    @Override
    public Field<String,Container> fieldTextRequired(final String name, final Character key){
        return TextField.factoryRequired(_lang,name, key);
    }
    
    @Override
    public Field<Date,Container> fieldTimeRequired(final String name, final Character key){
        return TimeField.factoryRequired(_lang,name,key);
    }
    
    @Override
    public Field<BigDecimal,Container> fieldPercentageRequired(final String name, final Character key){
        return PercentField.factoryRequired(_lang,name,key);
    }
    
    @Override
    public Field<Integer,Container> fieldIntegerRequired(final String name, final Character key){
        return IntegerField.factoryRequired(_lang,name,key);
    }

  @Override
  public Frame<Container> elemBigText(String txt) {
    return BigTextElem.factory(txt);
  }

  @Override
  public Frame<Container> elemTitle(String txt) {
    return TitleElem.factoryTxt(txt);
  }

  @Override
  public Field<String, Container> fieldName(String name, Character key) {
    return NameField.factory(_lang, name, key);
  }

  @Override
  public Field<String, Container> fieldAdresse(String name, Character key) {
    return AdresseField.factory(_lang, name, key);
  }

  @Override
  public Field<String, Container> fieldCP(String name, Character key) {
    return CpField.factory(_lang, name, key);
  }

  @Override
  public Field<String, Container> fieldTelephone(String name, Character key) {
    return TelephoneField.factory(_lang, name, key);
  }

  @Override
  public Field<String, Container> fieldUrl(String name, Character key) {
    return UrlField.factory(_lang, name, key);
  }

  @Override
  public Field<String, Container> fieldEmail(String name, Character key) {
    return EmailField.factory( _lang, name, key);
  }

  @Override
  public Field<String, Container> fieldNameRequired(String name, Character key) {
    return NameField.factoryRequired( _lang, name, key);
  }

  @Override
  public Field<String, Container> fieldAdresseRequired(String name, Character key) {
    return AdresseField.factoryRequired( _lang, name, key);
  }

  @Override
  public Field<String, Container> fieldCPRequired(String name, Character key) {
    return CpField.factoryRequired( _lang, name, key);
  }

  @Override
  public Field<String, Container> fieldTelephoneRequired(String name, Character key) {
    return TelephoneField.factoryRequired( _lang, name, key);
  }

  @Override
  public Field<String, Container> fieldUrlRequired(String name, Character key) {
    return UrlField.factoryRequired( _lang, name, key);
  }

  @Override
  public Field<String, Container> fieldEmailRequired(String name, Character key) {
    return EmailField.factoryRequired( _lang, name, key);
  }

}
